<template>
  <div class="visit-date">
    <p>参观日期</p>
    <p>
      <span>
        {{ dateFormat(form.visitDate, "YYYY-M-D") }}&nbsp;{{ form.visitPeriod }}
      </span>
    </p>
  </div>
  <div class="team-info">
    <p>团体信息</p>
    <div class="info-box">
      <van-cell-group>
        <van-cell title="团队名称" :value="form.teamName" />
        <van-cell title="团队人数" :value="form.peopleNum" />
        <van-cell title="领队姓名" :value="form.leaderName" />
        <van-cell title="领队电话" :value="form.leaderPhone" />
        <van-cell
          title="序厅讲解"
          :value="form.isExplain == 0 ? '不需要' : '需要'"
        />
      </van-cell-group>
    </div>
    <div class="page-bottom">
      <van-checkbox v-model="checked">
        <span class="tip">我已阅读并同意</span>
        <span class="tip desc" @click.stop="showMessage"
          >《数据隐私安全声明》</span
        >
      </van-checkbox>
      <div class="button-group">
        <van-button type="default" @click="router.back()" size="large" round
          >返回修改</van-button
        >
        <div style="width: 30px"></div>
        <van-button type="primary" @click="onSave" size="large" round
          >提交预约</van-button
        >
      </div>
    </div>
  </div>
  <Statement ref="refStatement" />
</template>

<script setup lang="ts">
import { ref, toRaw } from "vue";
import { useOrderStore } from "@/stores/order";
import router from "@/router";
import { orderInfoSave } from "@/request/api/order";
import { type OrderDTO } from "@/interface/order";
import { showNotify } from "vant";
import Statement from "./components/statement.vue";
import { dateFormat } from "@/utils/dateFormat";

const checked = ref(true);
const refStatement = ref();
const form = useOrderStore().orderGetter;

const showMessage = () => {
  refStatement.value.showDialog();
  return false;
};

const onSave = () => {
  if (!checked.value) {
    showNotify({ type: "danger", message: "请阅读并勾选数据隐私安全声明" });
    return;
  }
  const data: OrderDTO = toRaw(form);
  orderInfoSave(data).then((res: any) => {
    router.push("/flow/complete");
  });
};
</script>

<style lang="scss" scoped>
.visit-date {
  margin: 10px;

  p:first-child {
    color: #000;
    font-size: 16px;
    font-weight: 600;
  }

  p:last-child {
    font-size: 16px;
    line-height: 28px;
  }
}

.team-info {
  margin: 10px;

  > p {
    color: #000;
    font-size: 16px;
    font-weight: 600;
    line-height: 28px;
  }

  .info-box {
    width: 100%;
  }

  .tip {
    font-size: 14px;
    color: #282828;

    &.desc {
      color: var(--base-color);
    }
  }

  .item-label {
    margin-left: 8px;
    font-size: 16px;
    color: #333;
  }
}

.page-bottom {
  width: 360px;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 20px;
  overflow: hidden;

  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: center;
  }
}
</style>
